package com.qdu.servlet;

import com.qdu.entity.Employee;
import com.qdu.service.EmployeeService;
import com.qdu.servlet.EmployeeServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 该Servlet负责处理添加新员工的请求
 *
 * @author Anna
 */
@WebServlet("/aes")
public class AddEmployeeServlet extends HttpServlet {

    EmployeeService employeeService = new EmployeeServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ///1. 获取请求参数
        req.setCharacterEncoding("utf-8");
        String eid = req.getParameter("empId");
        String ename = req.getParameter("empName");
        String egender = req.getParameter("empGender");
        String dob=req.getParameter("empDob");

        //获取员工的4项信息，封装成一个Employee对象
        Employee employee = new Employee(eid, ename, egender, null, "default.jpg");

        //2. 调用业务逻辑，完成请求处理
        int rows=employeeService.addNewEmployee(employee);

   HttpSession session=req.getSession();//创建session
     session.setAttribute("name",ename);

        //3. 生成响应内容，这里返回受影响的行数用于判断是否修改成功
        resp.getWriter().print(rows);
    }
}
